"""
file: basePage.py
Author: 城下秋草
Desc: 页面对象基类
"""
from playwright.sync_api import Page


class BasePage:
    def __init__(self,page:Page):
        self.page = page

    def get_element(self,locator,locator_type):
        match locator_type:
            case "id":
                element = self.page.locator(f"#{locator}")
            case "class":
                element = self.page.locator(f".{locator}")
            case "text":
                element = self.page.get_by_text(locator)
            case "test-id":
                element = self.page.locator(f"[data-test={locator}]")
            case "selector":
                element = self.page.locator(locator)
            case _:
                raise TypeError
        return element